package com.huawei.cloud.phone.management.infrastructure.db;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.sql.init.SqlDataSourceScriptDatabaseInitializer;
import org.springframework.boot.autoconfigure.sql.init.SqlInitializationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

@Configuration
@EnableConfigurationProperties(SqlInitializationProperties.class)
public class SqlInitConfig {

    @Bean
    SqlDataSourceScriptDatabaseInitializer initSqlScript(@Qualifier("masterDataSource")DataSource dataSource,
                                                         @Autowired SqlInitializationProperties properties) {
        return new SqlDataSourceScriptDatabaseInitializer(dataSource, properties);
    }
}
